#!/usr/bin/env node

const inquirer = require('inquirer')
const ejs = require('ejs')
const fs = require('fs')
const path = require('path')


inquirer.prompt([
    {
        type: 'input',
        name: 'name',
        message: 'Project name',
        default: 'yyds-project'
    }, {
        type: 'input',
        name: 'version',
        message: 'Project version',
        default: '1.0.0'
    }, {
        type: 'input',
        name: 'description',
        message: 'Project description',
        default: ''
    }
]).then((userConfig) => {
    console.log(userConfig)
    //模板目录
    const tmplDir = path.join(__dirname, 'templates')
    console.log(tmplDir)
    //目标目录
    const destDir = process.cwd()
    console.log(destDir)

    // 读取文件
    fs.readdir(tmplDir, (err, files) => {
        if (err) throw err
        files.forEach(file => {
            console.log(files)
            ejs.renderFile(path.join(tmplDir, file), userConfig, (err, result) => {
                if (err) throw err
                fs.writeFileSync(path.join(destDir, file), result)
            })
        })
    })

})